//
//  RBChangePhoneVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/15.
//

#import "RBChangePhoneVC.h"
#import <UIColor+YYAdd.h>
#import "RBThemeConfig.h"
#import <UIControl+YYAdd.h>
#import "UIView+RBAdd.h"
#import "RBDefine.h"
#import <Masonry.h>
#import "UIButton+RBAdd.h"
#import "RBProfileVC.h"
#import "UIScrollView+RBAdd.h"
#import "RBTextField.h"
#import "RBTimerButton.h"

@interface RBChangePhoneVC ()

@property(nonatomic, strong)UIView *phoneView;
@property(nonatomic, strong)RBTextField *phoneF;
@property(nonatomic, strong)RBTimerButton *timerBtn;
@property(nonatomic, strong)UIView *smsView;
@property(nonatomic, strong)RBTextField *smsF;
@property(nonatomic, strong)UIButton *confirmBtn;

@end

@implementation RBChangePhoneVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
}

#pragma mark - Private

- (void)setup
{
    self.title = @"更换手机号";
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem.alloc initWithImage:[[UIImage imageNamed:@"settingQuestion"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(questionBtnTapped)];
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:nil forState:UIControlStateNormal];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    [self.view view_addView:self.phoneView withHeight:Zoom(60) width:kRBMainScreenWidth top:Zoom(10) bottom:0 left:0 right:0 centerX:0];
    self.timerBtn.customSettingBlock = ^(RBTimerButton *btn, NSTimeInterval cdF, NSInteger cdI, BOOL countingDown) {
        if (countingDown)
        {
            [btn rbSetTitle:[NSString stringWithFormat:@"%zdS后重发", cdI]];
        }
        else
        {
            [btn rbSetTitle:@"获取验证码"];
        }
    };
    self.timerBtn.timerKey = NSStringFromClass(self.class);
    [self.timerBtn config];
    [self.view view_addView:self.smsView withHeight:Zoom(60) width:kRBMainScreenWidth top:0 bottom:CGFLOAT_MIN left:0 right:0 centerX:0];
    self.confirmBtn.hidden = NO;
}

#pragma mark - Network

#pragma mark - Event

- (void)questionBtnTapped
{
    
}

- (void)timerBtnTapped
{
    [self.timerBtn startTimer];
}

- (void)confirmBtnTapped
{
    
}

#pragma mark - Setter

#pragma mark - Getter

- (UIView *)phoneView
{
    if (!_phoneView)
    {
        self.phoneView = ({
            UIView *view = UIView.new;
            view.backgroundColor = UIColor.whiteColor;
            
            RBTimerButton *timerBtn = RBTimerButton.new;
            self.timerBtn = timerBtn;
            [timerBtn rbAddTarget:self action:@selector(timerBtnTapped)];
            [view addSubview:timerBtn];
            [timerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-Zoom(18));
                make.centerY.mas_equalTo(0);
                make.height.mas_equalTo(Zoom(32));
                make.width.mas_equalTo(Zoom(90));
            }];
            [timerBtn rbSetTitleColor:UIColor.whiteColor];
            [timerBtn rbSetFont:[UIFont systemFontOfSize:Zoom(13)]];
            [timerBtn rbSetCornerRadius:Zoom(16)];
            timerBtn.backgroundColor = [UIColor colorWithHexString:@"#518CFF"];
            
            RBTextField *textF = RBTextField.new;
            self.phoneF = textF;
            textF.type = RBTextFieldTypePhone;
            textF.font = [UIFont systemFontOfSize:Zoom(14)];
            textF.textColor = [RBThemeConfig textBlackColor];
            textF.placeholder = @"请输入新手机号";
            [view addSubview:textF];
            [textF mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(0);
                make.left.mas_equalTo(Zoom(18));
                make.right.mas_equalTo(timerBtn.mas_left).offset(Zoom(-18));
            }];
            
            view;
        });
    }
    return _phoneView;
}

- (UIView *)smsView
{
    if (!_smsView)
    {
        self.smsView = ({
            UIView *view = UIView.new;
            view.backgroundColor = UIColor.whiteColor;
            
            RBTextField *textF = RBTextField.new;
            self.smsView = textF;
            textF.type = RBTextFieldTypePhone;
            textF.maxTextLength = 8;
            textF.font = [UIFont systemFontOfSize:Zoom(14)];
            textF.textColor = [RBThemeConfig textBlackColor];
            textF.placeholder = @"请输入验证码";
            [view addSubview:textF];
            [textF mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(0);
                make.left.mas_equalTo(Zoom(18));
                make.right.mas_equalTo(Zoom(-18));
            }];
            
            view;
        });
    }
    return _smsView;
}

- (UIButton *)confirmBtn
{
    if (!_confirmBtn)
    {
        self.confirmBtn = ({
            UIButton *view = UIButton.new;
            [view rbAddTarget:self action:@selector(confirmBtnTapped)];
            [view rbSetTitle:@"确认修改"];
            [view rbSetTitleColor:UIColor.whiteColor];
            [view rbSetFont:[UIFont systemFontOfSize:Zoom(15)]];
            [view rbSetCornerRadius:Zoom(22)];
            view.backgroundColor = [UIColor colorWithHexString:@"#518CFF"];
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(-MAX(Zoom(25), kRBSafeBottomHeight));
                make.centerX.mas_equalTo(0);
                make.size.mas_equalTo(CGSizeMake(Zoom(339), Zoom(44)));
            }];
            view;
        });
    }
    return _confirmBtn;
}

@end
